﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Matriculex.UI.Helpers
{
    public static class MatriculexContextHelper
    {
        private const string UserSession = "user";
        public static object CurrentUser(this ControllerContext context)
        {
            return context.HttpContext.Session[UserSession];
        }

        public static T CurrentUser<T>(this ControllerContext context)
            where T : class
        {
            return context.HttpContext.Session[UserSession] as T;
        }

        public static void RegisterUser(this ControllerContext context, object user)
        {
            context.HttpContext.Session[UserSession] = user;
        }

        public static void UnregisterUser(this ControllerContext context)
        {
            context.HttpContext.Session[UserSession] = null;
        }

        public static bool IsAuthenticated(this ControllerContext context)
        {
            return context.CurrentUser() == null;
        }
    }
}
